﻿using SimpleESBClient;
using SimpleESBCore.Common;
using SimpleESBCore.Implement.Serializer;
using SimpleESBCore.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinEsbClint
{
    public partial class frmClient : Form
    {
        IClient client;
        public frmClient()
        {
            InitializeComponent();
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            btnDisConnect.Enabled = true;
            btnConnect.Enabled = false;
            client.Connect();
        }

        private void frmClient_Load(object sender, EventArgs e)
        {
            ClientOption clientOption = new ClientOption();
            clientOption.ClientName = "EsbClient";
            clientOption.ServerIPAddress = IPAddress.Parse("127.0.0.1");
            clientOption.HeartPort = 9000;
            clientOption.DataPort = 9001;

            ILog log = new WinLog(txtMessage);
            ISerialization serialization = new JSONSerializer();

            client = new EsbClient(clientOption, log, serialization);
        }

        private void btnDisConnect_Click(object sender, EventArgs e)
        {
            btnDisConnect.Enabled = false;
            btnConnect.Enabled = true;
            client.DisConnect();
        }
    }
}
